using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;



    public class SelectableBox
    {
        public GameObject target { get; private set; }
        public Collider collider { get; private set; }
        protected bool createdBox;

        public void Binding(GameObject target)
        {
            if(this.target != null){
                UnBinding();
            }
            this.target = target;
            //创建盒子
            collider = target.GetComponent<Collider>();
            if(collider == null){
                createdBox = true;
                var box_collider = target.AddComponent<BoxCollider>();
                box_collider.center = new Vector3(0, 1, 0);
                box_collider.size = new Vector3(1, 2, 1);
                collider = box_collider;
            }
            else {
                createdBox = false;
            }
         
        }

        public void UnBinding()
        {
            this.target = null;
            //删除盒子
            if(createdBox && collider)
            {
                UnityEngine.Object.Destroy(collider);
            }
        }
}